<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.pro.bean.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link href="css/bootstrap.css" rel="stylesheet">
		<link rel="stylesheet" href="css/main.css">
		<link rel="stylesheet" href="css/datepicker.css">

		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/bootstrap-datepicker.js"></script>

		<title>名片管理系统</title>
	</head>
<script language="javascript">
	//alert("load");
	function loadIframe(iframeName, url) {
    var $iframe = $('#' + iframeName);
    if ( $iframe.length ) {
        $iframe.attr('src',url);
       // alert(url);   
        return false;
    }
    return true;
}
$(function(){
	var url = "servlet/GetAllUnitsServlet";
	$.post(url,null,function(data){
		var objs = eval(data);
		for(var i=0;i<objs.length;++i)
		{
			$("#department").append("<option value='"+objs[i]+"'>"+objs[i]+"</option>");
		}
	});
	
	$("#department").change(function()
	{
		var arg = $(this).children('option:selected').val();
		alert(arg);
		var url = "servlet/GetUsersServlet?arg="+encodeURI(arg);
		$.post(url,arg,function(data){
			var objs = eval(data);
			$("#person").empty();
			for(var i=0;i<objs.length;++i)
			{
				$("#person").append("<option value='"+objs[i]+"'>"+objs[i]+"</option>");
			}
		});
	});
	
	
	$("#searchbtn").click(function(){
	
		var dateselect = $("#date");
		var dates = $("#datestart");
		var datee = $("#dateend");
		var cardcmpname = $("#cmpname");
		var cardname = $("#name");
		var name = $("#person");
		var cmpstr = "";
		var cardnamestr = "";
		var datestr = "";
		var datearg = "&datearg="+$("#date").val();
		cmpstr = "&cmp="+cardcmpname.val();
		cardnamestr = "&cardname="+cardname.val();
		datestr = "&dates="+dates.val()+"&datee="+datee.val();
		
		if(dateselect.val() != "--" 
				&&( dates.val().length==0 || datee.val().length==0))
			alert("请选择起始日期");
		var url = "servlet/GetCardServlet?name="+name.val()
				+cmpstr+cardnamestr+datestr+datearg;
		loadIframe("cc",url);
		});
	
	$("#datestart").click(function(){
		$("#datestart").datepicker({
			format:'yyyy-mm-dd'
		});
	});
	$("#dateend").click(function(){
		$("#dateend").datepicker({
			format:'yyyy-mm-dd'
		});
	});
});
</script>
	<body>
	<input type="hidden" id="username"  value="<%=((Users)request.getSession().getAttribute("Users")).getUsername() %>" ></input>
		<div id="searchdiv" style="background-color: #efefef; height: 110px">
			<form id="cardsearchform" name="cardsearchform">
				<div style="width: 300px; float: left;margin-left:15px;" >
					<p>
						<strong>部门选择</strong>
					</p>
					<p>
						<select style="width: 200px" id="department">
							<option value="my">
								自己所有名片
							</option>
							<option value="all">
								全部
							</option>
						</select>
					</p>
					<p>
						<select style="width: 200px" id="person">
							<option value="my">
								my
							</option>
						</select>
						<!-- 
						&nbsp;&nbsp;
						<input type="checkbox" id="includemy" />
						<span>包含我自己的所有名片</span>
						 -->
					</p>
				</div>
				<div style="width: 455px; float: right">
					<p>
						<strong>检索</strong>
					</p>
					<p>
						<span>公司: </span>
						<input id="cmpname" type="text" />
						<span>姓名: </span>
						<input id="name" type="text" />
					</p>
					<p>
						<span>日期: </span>
						<select id="date" style="width: 67px">
							<option >
								--
							</option>
							<option >
								登陆日
							</option >
							<option>
								更新日
							</option>
						</select>
						<input id="datestart" style="width: 87px" id="datestart" type="text" />
						<span>--</span>
						<input id="dateend" style="width: 87px" id="dateend" type="text" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button  id="searchbtn" type="button" class="btn btn-primary btn-sm">
							&nbsp;检索&nbsp;
						</button>
						<!-- button >asdf</button> -->
					</p>
				</div>
			</form>
		</div>
		<p></p>
		<!-- ####################### -->
		<iframe id="cc" src="servlet/GetCardServlet?name=all&cardname=&cmp=&dates=&datee=&datearg=0"
				name="cc" width="900px" height="500px" frameborder="no" >
		</iframe>
	</body>
</html>
